﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;

namespace YJKArch.BalAndStepModule
{
	public partial class CreateAbnormalBalconyForm : System.Windows.Forms.Form
	{
		public CreateAbnormalBalconyForm(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			this.rvt_doc = doc;
		}

		private void CreateAbnormalBalconyForm_Load(object sender, EventArgs e)
		{
			this.BalconyType = "凸阳台";
			Helper.AddCombItems(IListDate.WallTypeList, this.comboBox2);
			Helper.AddCombItems(IListDate.FloorTypeList, this.cmbWallType);
			this.wallTypestr = this.comboBox2.SelectedItem.ToString();
			this.bCheckDeleteModelLine = this.checkBoxDelModelLine.Checked;
			try
			{
				this.wallHeight = Uint.mmToFeet(double.Parse(this.txtWallHeight.Text), (Autodesk.Revit.DB.DisplayUnitType)71);
				this.levelElevation = Uint.mmToFeet(double.Parse(this.txtLevel.Text), (Autodesk.Revit.DB.DisplayUnitType)71);
			}
			catch (Exception)
			{
			}
			this.ReadDlgData();
		}

		private void CreateAbnormalBalconyForm_FormClosed(object sender, FormClosedEventArgs e)
		{
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void CreateAbnormalBalconyForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SaveDlgData();
		}

		private void SaveDlgData()
		{
			FileStream fileStream = new FileStream(Path.GetTempPath() + "cbf.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			string value = this.checkBoxDelModelLine.Checked ? "1" : "0";
			streamWriter.WriteLine(value);
			streamWriter.WriteLine(this.txtWallHeight.Text);
			streamWriter.WriteLine(this.txtLevel.Text);
			streamWriter.WriteLine(this.cmbWallType.SelectedIndex.ToString());
			streamWriter.WriteLine(this.comboBox2.SelectedIndex.ToString());
			streamWriter.WriteLine(base.Location.X);
			streamWriter.WriteLine(base.Location.Y);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private bool ReadDlgData()
		{
			string path = Path.GetTempPath() + "cbf.dat";
			if (!File.Exists(path))
			{
				base.StartPosition = FormStartPosition.CenterScreen;
				return true;
			}
			base.StartPosition = FormStartPosition.Manual;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int num = Convert.ToInt32(streamReader.ReadLine());
			this.checkBoxDelModelLine.Checked = (num == 1);
			this.txtWallHeight.Text = streamReader.ReadLine();
			this.txtLevel.Text = streamReader.ReadLine();
			num = Convert.ToInt32(streamReader.ReadLine());
			if (this.cmbWallType.Items.Count > num)
			{
				this.cmbWallType.SelectedIndex = num;
			}
			num = Convert.ToInt32(streamReader.ReadLine());
			if (this.comboBox2.Items.Count > num)
			{
				this.comboBox2.SelectedIndex = num;
			}
			try
			{
				int x = Convert.ToInt32(streamReader.ReadLine());
				int y = Convert.ToInt32(streamReader.ReadLine());
				base.Location = new System.Drawing.Point(x, y);
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
				return true;
			}
			streamReader.Close();
			fileStream.Close();
			return true;
		}

		private void txtDistince_KeyPress(object sender, KeyPressEventArgs e)
		{
			Helper.TxtSetNum(sender, e);
		}

		private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
		{
			Helper.TxtSetNum(sender, e);
		}

		private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
		{
			Helper.TxtSetNum(sender, e);
		}

		private void cmbWallType_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.wallTypestr = this.comboBox2.SelectedItem.ToString();
		}

		private void txtWallHeight_TextChanged(object sender, EventArgs e)
		{
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void CreateAbnormalBalconyForm_MouseLeave(object sender, EventArgs e)
		{
			try
			{
				if (this.txtWallHeight.Text != "")
				{
					this.wallHeight = Uint.mmToFeet(double.Parse(this.txtWallHeight.Text), (Autodesk.Revit.DB.DisplayUnitType)71);
				}
				else
				{
					this.wallHeight = 0.0;
				}
				if (this.txtLevel.Text != "")
				{
					this.levelElevation = Uint.mmToFeet(double.Parse(this.txtLevel.Text), (Autodesk.Revit.DB.DisplayUnitType)71);
				}
				else
				{
					this.levelElevation = 0.0;
				}
				this.floorType = this.cmbWallType.SelectedItem.ToString();
				this.wallTypestr = this.comboBox2.SelectedItem.ToString();
				this.bCheckDeleteModelLine = this.checkBoxDelModelLine.Checked;
			}
			catch (Exception)
			{
			}
		}

		private void CreateAbnormalBalconyForm_MouseEnter(object sender, EventArgs e)
		{
		}

		private void txtLevel_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.levelElevation = Uint.mmToFeet(double.Parse(this.txtLevel.Text), (Autodesk.Revit.DB.DisplayUnitType)71);
			}
			catch (Exception)
			{
				this.errorProvider1.SetError(this.txtLevel, "格式错误");
			}
			this.errorProvider1.SetError(this.txtLevel, string.Empty);
		}

		private void buttonOk_Click(object sender, EventArgs e)
		{
			this.SaveDlgData();
		}

		public string wallTypestr;

		public double wallHeight;

		public string BalconyType;

		public double levelElevation;

		public string floorType;

		public bool bCheckDeleteModelLine;

		private Document rvt_doc;
	}
}
